<?php
include_once('lib.php');

function displayMenuItems($items)
	{
	foreach($items as $item)
		{
		preg_match('/href="(.*?)"/', $item, $matches);
		//print '<hr />'.str_replace('&amp;format=none', '', $matches[1]);

		if	(
				(
					isset($_GET['format']) &&
					stringContains($_SERVER['REQUEST_URI'], html_entity_decode($matches[1]))
				)
				||
				(
					!isset($_GET['format']) &&
					stringContains($_SERVER['REQUEST_URI'], str_replace('&amp;format=none', '', $matches[1]))
				)
				||
				(
					(
					stringStartsWith(basename($_SERVER['REQUEST_URI']), 'demo.php') ||
					stringStartsWith(basename($_SERVER['REQUEST_URI']), 'view.php')
					)
					&&
					(
					basename($matches[1]) == 'demo.php'
					)
				)
			)
			{
			$item = str_replace($matches[1], $matches[1].'" class="current', $item);  
			}
		print $item;
		
		}
	}

?>
<div class="header">
	<h1 id="logo"><img src="pilferpage-logo.png" alt="PilferPage"/></h1>
	<div id="menu">
		<ul id="menu1">
		<?php
		displayMenuItems( Array(
			'<li><a href="index.php">About</a></li>',
			'<li><a href="demo.php">Demo</a></li>',
			'<li><a href="pilferpage.tar.gz">Download</a></li>'
			));
		?>
		</ul>

		<?php
		if(stringContains($_SERVER['REQUEST_URI'], 'demo.php') || stringContains($_SERVER['REQUEST_URI'], 'view.php'))
			{
		?>
		<ul id="menu2">
			<?php
			displayMenuItems( Array(
				'<li><a href="view.php?file=headings">Headings</a></li>',
				'<li><a href="view.php?file=tables">Tables</a></li>',
				'<li><a href="view.php?file=hierarchical-tables-rows">Complex Tables</a></li>',
				'<li><a href="view.php?file=media">Media</a></li>'

				))
			?>
		</ul>
		<?php
			}

		if(isset($_GET['file']))
			{
		?>
		<ul id="menu3">
			<?php
			displayMenuItems( Array(
				'<li><a href="view.php?file='.$_GET['file'].'&amp;format=none">Source File</a></li>',
				'<li><a href="view.php?file='.$_GET['file'].'&amp;format=html32">HTML 3.2</a></li>',
				'<li><a href="view.php?file='.$_GET['file'].'&amp;format=html401">HTML 4.01</a></li>',
				'<li><a href="view.php?file='.$_GET['file'].'&amp;format=xhtml1">XHTML 1</a></li>',
				'<li><a href="view.php?file='.$_GET['file'].'&amp;format=html5">HTML 5</a></li>',
				'<li><a href="view.php?file='.$_GET['file'].'&amp;format=xhtml5">XHTML 5</a></li>',
				'<li><a href="view.php?file='.$_GET['file'].'&amp;format=xslfo11">XSL-FO 1.1 (PDF)</a></li>',
				'<li><a href="view.php?file='.$_GET['file'].'&amp;format=flex2">Flex 2</a></li>',
				'<li><a href="view.php?file='.$_GET['file'].'&amp;format=xul1">XUL 1</a></li>',
				'<li><a href="view.php?file='.$_GET['file'].'&amp;format=csv">CSV</a></li>',
				'<li><a href="view.php?file='.$_GET['file'].'&amp;format=docbook5">DocBook 5</a></li>',
				'<li><a href="view.php?file='.$_GET['file'].'&amp;format=odt11" title="Open Document (ODF): Word Processing">ODT 1.1 (ODF)</a></li>',
				'<li><a href="view.php?file='.$_GET['file'].'&amp;format=ods11" title="Open Document (ODF): Spreadsheet">ODS 1.1 (ODF)</a></li>',
				'<li><a href="view.php?file='.$_GET['file'].'&amp;format=rss2">RSS 2.0</a></li>',
				'<li><a href="view.php?file='.$_GET['file'].'&amp;format=atom1">ATOM 1</a></li>'
				))
			?>
		</ul>
		<?php
			}
		?>
	</div>
</div>

